<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table id="list">

</table>
</body>
<script>

    var employees = [
        {
            id:1,
            name:'L',
            age:34
        },{
            id:2,
            name:'M',
            age:35
        }
    ]
    renderTable(employees);

    function renderTable(arr) {
        var list  = document.getElementById('list');
        list.innerHTML = "";

        for (var i in arr){
            var tRow = document.createElement('tr');
            var tdataName = document.createElement('td');
            var tdataAge = document.createElement('td');
            var tdataCommand = document.createElement('td');

            tdataName.innerText = arr[i].name;
            tdataAge.innerText = arr[i].age
            var btnRemove = document.createElement('button');
            var empId = document.createElement('input');
            empId.type = "hidden";
            empId.value = i;
            btnRemove.innerText = "删除";
             btnRemove.onclick = function(){

                 if(confirm("是否删除本条数据？")){
                     btnRemoveClick(arr,this,i);
                 }

             }
            tdataCommand.appendChild(btnRemove);
            tdataCommand.appendChild(empId);
            tRow.appendChild(tdataName);
            tRow.appendChild(tdataAge);
            tRow.appendChild(tdataCommand);
            list.appendChild(tRow);
        }
    }

function btnRemoveClick(arr,_this,i) {
    /*var currentRow = this.parentElement.parentElement;
                currentRow.parentElement.removeChild(currentRow);*/
    var empId= _this.nextElementSibling.value;
    var emp=  arr.find(function (item) {
        return item.id == empId;
    })
    arr.splice(i,1);
    renderTable(arr);
}


    /***
     * 删除
     *   1. 删除dom
     *   2. 改变数据
    * */

</script>
</html>